<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>医院档案</title>
    <link rel="stylesheet" href="/template/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">医院档案</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;"><?php echo @$_SESSION['username']; ?></a>
            </li>
            <li class="layui-nav-item"><a href="javascript:;" id="logout">退出</a></li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree">
                <li class="layui-nav-item layui-this"><a href="index.php">病例列表</a></li>
            </ul>
        </div>
    </div>
    <div class="layui-body" style="padding: 20px;">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>病例列表</legend>
        </fieldset>
        <table class="layui-hide" id="DataList" lay-filter="DataList"></table>
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="add">创建病例</button>
            </div>
        </script>
        <script type="text/html" id="bar">
            <?php if ($_SESSION['admin_role'] == 1) { ?><a class="layui-btn layui-btn-xs layui-btn-warm"
                                                           lay-event="sendDingDan">发布订单</a><?php } ?>
            <?php if ($_SESSION['admin_role'] == 2) { ?><a class="layui-btn layui-btn-xs layui-btn-warm"
                                                           lay-event="lookDingDan">查看订单</a><?php } ?>
            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="fangan">方案</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
    <div class="layui-footer">© 医院档案</div>
</div>
<script src="/template/layui/jquery-1.7.2.min.js"></script>
<script src="/template/layui/layui.js"></script>
<script>
    layui.use(['element', 'table', 'form'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#DataList',
            url: '?act=getList',
            toolbar: '#toolbar',
            cols: [[
                {field: 'case_list_id', title: 'ID'},
                {field: 'name', title: '姓名'},
                {field: 'age', title: '年龄'},
                {field: 'symptom', title: '症状'},
                {field: 'last_time', title: '最后操作时间'},
                {
                    field: 'status', title: '状态', templet: function (e) {
                        switch (e.status) {
                            case '0':
                                return '等待医生出方案';
                                break;
                            case '1':
                                return '等待专家回复方案';
                                break;
                            case '2':
                                return '等待医生回复专家';
                                break;
                            case '3':
                                return '方案被确定';
                                break;
                        }
                    }
                },
                {
                    field: 'order_status', title: '订单', templet: function (e) {
                        switch (e.order_status) {
                            case '0':
                                return '医生未发布';
                                break;
                            case '1':
                                return '医生已发布';
                                break;
                            case '2':
                                return '专家已确定';
                                break;
                        }
                    }
                },
                {fixed: 'right', title: '操作', toolbar: '#bar', width: 300}
            ]]
            , page: true
        });
        table.on('toolbar(DataList)', function (obj) {
            switch (obj.event) {
                case 'add':
                    window.location.href = 'caseEdit.php';
                    break;
            }
        });
        table.on('tool(DataList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    if (index) {
                        var loadIndex = layer.load(1, {
                            shade: [0.5, '#000']
                        });
                        $.ajax({
                            url: '?act=deleteDo',
                            data: {
                                case_list_id: data.case_list_id
                            },
                            dataType: 'json',
                            success: function (res) {
                                layer.close(loadIndex);
                                obj.del();
                                layer.close(index);
                            }
                        });
                    }
                });
            } else if (obj.event === 'edit') {
                window.location.href = 'caseEdit.php?case_list_id=' + data.case_list_id;
            } else if (obj.event === 'fangan') {
                window.location.href = 'schemeList.php?case_list_id=' + data.case_list_id;
            } else if (obj.event === 'sendDingDan') {
                form.val('form', {
                    case_list_id: data.case_list_id,
                    model: data.model,
                    price: data.price
                });
                layer.open({
                    type: 1,
                    title: '发布订单',
                    content: $('#sendDingdan')
                });
            } else if (obj.event === 'lookDingDan') {
                if (data.order_status == 0) {
                    layer.msg('医生未发布，请等待医生发布！');
                } else {
                    form.val('formLook', {
                        case_list_id: data.case_list_id,
                        model: data.model,
                        price: data.price
                    });
                    layer.open({
                        type: 1,
                        title: '查看订单',
                        content: $('#lookDingdan')
                    });
                }
            }
        });
        form.on('submit(submit)', function (data) {
            var loadIndex = layer.load(1, {
                shade: [0.5, '#000']
            });
            $.ajax({
                url: '?act=sendDingdan',
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    window.location.href = window.location.href;
                }
            });
            return false;
        });
        form.on('submit(orderSubmit)', function (data) {
            var loadIndex = layer.load(1, {
                shade: [0.5, '#000']
            });
            $.ajax({
                url: '?act=orderSubmit',
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    window.location.href = window.location.href;
                }
            });
            return false;
        });
        form.on('submit(orderCancel)', function (data) {
            layer.confirm('确定取消？', {icon: 3, title:'提示'}, function(index){
                if (index == 2) {
                    layer.close(index);
                    var loadIndex = layer.load(1, {
                        shade: [0.5, '#000']
                    });
                    $.ajax({
                        url: '?act=orderCancel',
                        data: data.field,
                        dataType: 'json',
                        success: function (res) {
                            window.location.href = window.location.href;
                        }
                    });
                }
            });
            return false;
        });
    });
    $(function () {
        $('#logout').bind('click', function () {
            var loadIndex = layer.load(1, {
                shade: [0.5, '#000']
            });
            $.ajax({
                url: 'logout.php',
                success: function (res) {
                    window.location.href = 'login.php';
                }
            });
        });
    });
</script>
</body>



<div id="sendDingdan" style="display: none;">
    <form class="layui-form" action="" style="padding: 20px;" lay-filter="form">
        <input type="hidden" name="case_list_id" value="">
        <div class="layui-form-item">
            <label class="layui-form-label">型号</label>
            <div class="layui-input-block">
                <input type="text" name="model" placeholder="请输入型号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" placeholder="请输入价格" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<div id="lookDingdan" style="display: none;">
    <form class="layui-form" action="" style="padding: 20px;" lay-filter="formLook">
        <input type="hidden" name="case_list_id" value="">
        <div class="layui-form-item">
            <label class="layui-form-label">型号</label>
            <div class="layui-input-block">
                <input type="text" name="model" disabled placeholder="请输入型号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" disabled placeholder="请输入价格" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="orderSubmit">确定</button>
                <button type="reset" class="layui-btn layui-btn-primary" lay-submit="" lay-filter="orderCancel">取消</button>
            </div>
        </div>
    </form>
</div>

</html>